import request from '@/utils/request'
import { saveAs } from 'file-saver'

// 创建规则
export function createRule(data) {
    return request({
        url: '/admin-api/alert/rules/create',
        method: 'post',
        data
    })
}

// 获取规则列表
export function getRuleList(params) {
    return request({
        url: '/admin-api/alert/rules/page',
        method: 'get',
        params
    })
}

// 更新规则
export function updateRule(data) {
    return request({
        url: '/admin-api/alert/rules/update',
        method: 'put',
        data
    })
}

// 删除规则
export function deleteRule(data) {
    return request({
        url: '/admin-api/alert/rules/delete?id=' + data,
        method: 'delete'
    })
}

// 下载文件
export function exportRule(data) {
    return request({
        url: '/admin-api/alert/rules/export-excel',
        method: 'get',
        params: data,
        responseType: 'blob',
    }).then(res => {
        const blob = new Blob([res], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8" })
        saveAs(blob, decodeURIComponent('告警规则.xlsx'))
    })
}


// 获取告警动作类型
export function getActionTypes(params) {
    return request({
        url: '/admin-api/system/dict-type/type',
        method: 'get',
        params
    })
}

// 获取告警动作目标用户
export function getActionUsers(params) {
    return request({
        url: '/admin-api/system/user/list-all-simple',
        method: 'get',
        params
    })
}

// 创建告警动作
export function createAction(data) {
    return request({
        url: '/admin-api/alert/actions/create',
        method: 'post',
        data
    })
}

// 更新告警动作
export function updateAction(data) {
    return request({
        url: '/admin-api/alert/actions/update',
        method: 'put',
        data
    })
}

// 获取告警动作分页
export function getActionList(params) {
    return request({
        url: '/admin-api/alert/actions/page',
        method: 'get',
        params
    })
}

// 删除告警动作
export function deleteAction(data) {
    return request({
        url: '/admin-api/alert/actions/delete?id=' + data,
        method: 'delete'
    })
}

// 获取告警记录分页
export function getRecordList(params) {
    return request({
        url: '/admin-api/alert/logs/page',
        method: 'get',
        params
    })
}

// 更新告警日志状态 /admin-api/alert/logs/update
export function updateRecordStatus(data) {
    return request({
        url: '/admin-api/alert/logs/update',
        method: 'put',
        data
    })
}

//删除告警日志
export function deleteRecord(data) {
    return request({
        url: '/admin-api/alert/logs/delete?id=' + data,
        method: 'delete'
    })
}


// 获取硬件类型
export function getHardwareTypes(params) {
    return request({
        url: '/admin-api/system/dict-type/type',
        method: 'get',
        params
    })
}